package practite.Demo;
import day05.MapOfArrayDemo.*;

import javax.sound.midi.Soundbank;
import java.util.Arrays;
import java.util.Random;

import static day05.MapOfArrayDemo.pr;

public class Demo8 {
    public static void main(String[] args) {
        Random rd = new Random();
        int compareCount = 0;//对比次数
        int swapCount = 0;//换位自增

        long startTime = System.currentTimeMillis();//开始时间

        int[] array = new int[10];
        int sum = 0;//和
        for (int i = 0; i < array.length; i++) {
            array[i] = rd.nextInt(101);
        }
//        System.out.println(Arrays.toString(array));
//        System.out.println();
        //1.冒泡排序
        for (int i = 0; i < array.length-1; i++) {
            for (int j = 0; j < array.length-1-i; j++) {
                compareCount++;//执行自增
                if (array[j]<array[j+1]){
                    //执行换位
                    sum = array[j];
                    array[j] = array[j+1];
                    array[j+1] = sum;
                    swapCount++;//换位自增
                    System.out.println(Arrays.toString(array));//输出数组
                }
            }
            System.out.println();
        }
        //2.选择排序
        /*for (int i = 0; i < array.length-1; i++) {
            for (int j = i+1; j < array.length; j++) {
                compareCount++;//执行自增
                if (array[i]<array[j]){
                    //执行换位
                    sum = array[i];
                    array[i] = array[j];
                    array[j] = sum;
                    swapCount++;//换位自增
//                    System.out.println(Arrays.toString(array));//输出数组
                }
            }
//            System.out.println();
        }*/
        //3.插入排序
        /*for (int i = 1; i < array.length; i++) {
            for (int j = i-1  ; j >= 0; j--) {
                compareCount++;//执行自增
                if (array[j]<array[j+1]){
                        sum = array[j+1];
                        array[j+1] = array[j];
                        array[j] = sum;
                    swapCount++;//换位自增
                    System.out.println(Arrays.toString(array));

                }
            }
            System.out.println();
        }*/
        long downTime = System.currentTimeMillis();//结束时间

        System.out.println(compareCount);
        System.out.println(swapCount);
        System.out.println(downTime-startTime);
        pr(array);
    }
}
//1 1
//1 3
//2 5
//3 7
//4 9
//5 11
//6
/*
9 1
8 2
7 3
6 4
5 5
4 6
*/